<template>
  <div>
    <Button type="primary" class="back-button" @click="$router.push({name:'calculation'})" icon="md-arrow-back">返回上一级</Button>
    <Card :style="{height:cardHeight}">
      <div class="center card">
        <Icon type="md-calculator" style="font-size:80pt;" />
        <br><br>
        <span>请选择计算规则与范围：</span>
        <br><br>
        <dict code='JSGZ' model="ruleId" holder="请选择规则" :value="ruleId" @click="getVal" @getCode="getCode" style="width:150px;"></dict>
        <dict v-show="isShow" code='FW' model="ranktype" :data="fwData" holder="请选择范围" :value="ranktype" @click="getVal" style="width:150px;margin-left:20px;"></dict>

        <br>
        <br>
        <br>
        <Button type="primary" @click="goto" style="width:150px;">确定</Button>
      </div>
    </Card>
  </div>
</template>

<script>
import dict from "_c/dict/dict.vue";
import { getDict } from "@/api/configure";
import Api from "@/api/calculation";
import _ from "lodash";
const api = new Api();
// 赛事管理
export default {
  components: {
    dict
  },
  data() {
    return {
      loading: false,
      isQuery: false,
      ruleId: null,
      ranktype: null,
      isShow: true,
      fwData: [
        {
          dictCode: "FW",
          code: "0",
          name: "中高协排名",
          hasChildren: "0",
          parentCode: ""
        },
        {
          dictCode: "FW",
          code: "1",
          name: "中国排名",
          hasChildren: "0",
          parentCode: ""
        }
      ]
    };
  },
  mounted() {
    let self = this;
    self.init();
  },
  computed: {
    cardHeight: function() {
      return `${document.documentElement.clientHeight - 142}px`;
    }
  },
  methods: {
    // 获取字典选择的值
    getVal(expression) {
      let self = this;
      eval(expression);
      // if (self.ruleId !== null) {
      //   self.$router.push({
      //     path: `/integral-calculation-management/calculation/add/${
      //       self.ruleId
      //     }`
      //   });
      // }
    },
    // 初始化
    init() {
      let self = this;
    },
    getCode(kindCode) {
      // if (["1", "2"].includes(kindCode)) {
      //   this.isShow = true;
      // } else {
      //   this.isShow = false;
      // }
    },
    goto() {
      let self = this;
      let ranktype = self.ranktype;
      if (self.ruleId == null) {
        self.$Message.warning("请选择计算规则");
        return;
      }
      if (self.isShow && ranktype == null) {
        self.$Message.warning("请选择范围");
        return;
      }
      if (!self.isShow) {
        ranktype = 0;
      }
      self.$router.push({
        path: `/integral-calculation-management/calculation/add/${self.ruleId}/${ranktype}`
      });
    }
  }
};
</script>

<style scoped>
.card {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: -75px !important;
  margin-top: -150px !important;
}
</style>
